<template>
	<div>
		<div class="module-title">
			题目导航
			<span class="total">（共{{ questionTotal }}题）</span>
		</div>
		<div v-if="type === 'edit'" class="status-example">
			<div class="items">
				<div class="q-item checked" />选中
			</div>
			<div class="items">
				<div class="q-item" />未编辑
			</div>
			<div class="items">
				<div class="q-item complete" />已编辑
			</div>
		</div>
		<div v-for="(item1, index1) in data" :key="item1.questionType" class="type-wrap">
			<div class="title-box">
				{{ ChineseUtil.transformToChinese(index1 + 1 ) }}、{{ Dictionary.get('rc_questionType')[item1.questionType] }}
				<span
					class="total"
				>（{{ item1.questionTypeDataList.length }}题）</span>
			</div>
			<div class="items-box">
				<div
					v-for="item2 in item1.questionTypeDataList"
					:key="item2.navSeq"
					:class="['q-item',
						{circle: !['A','CF','L','C'].includes(item1.questionType)},
						{complete: item2.isComplete},
						{checked: item2.isChecked},
					]"
					@click="clickItem(item2, item1)"
				>
					{{ item2.navSeq }}
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		props: {
			// 展示类型，可选值 preview纯展示题目，edit展示编辑状态
			type: {
				type: String,
				default: "preview"
			},
			// 试题列表 [{questionType:试题类型,questionTypeDataList[]: 类型下的试题列表,questionTypeDataList[].navSeq：试题序号,questionTypeDataList[].isChecked：是否为选中状态,questionTypeDataList[].isComplete：是否为已编辑状态}]
			data: {
				type: Array,
				default: () => []
			}
		},
		computed: {
			// 试题总数
			questionTotal() {
				return this.data.reduce((result, item) => (result += item.questionTypeDataList.length), 0);
			}
		},
		methods: {
			// 点击标号
			clickItem(item2, item1) {
				this.$emit("click-item", item2, item1);
			}
		}
	};
</script>

<style lang="less" scoped>
	.q-item {
		height: 32px;
		padding: 0 10px;
		line-height: 32px;
		border: 1px solid #dfe0e6;
		background-color: #f4f5f9;
		color: #666;
		text-align: center;
		font-size: 14px;
		border-radius: 8px;
		cursor: pointer;

		&.circle {
			width: 32px;
			padding: 0;
			border-radius: 50%;
		}

		&.complete {
			border-color: #c2f4a9;
			background-color: #52c31b;
			color: #fff;
		}

		&.checked {
			border-color: #FF4436;
            background-color: #fff5f5;
            color: #FF4436;
		}
		&.checked.complete {
			border-color: #c2f4a9;
            background-color: #409018;
            color: #fff;
		}
	}
	.module-title {
		padding-left: 23px;
		margin-bottom: 4px;
		height: 37px;
		line-height: 37px;
		font-size: 14px;
		color: #000;
		font-weight: bold;
		background: linear-gradient(90deg, #edeef1, #ffffff 50%);
		position: relative;

		&::after {
			content: "";
			width: 2.5px;
			height: 13px;
			background-color: #000;
			position: absolute;
			left: 8px;
			top: 12px;
		}

		.total {
			font-size: 12px;
			font-weight: normal;
		}
	}

	.status-example {
		padding: 12px 0 8px;
		display: flex;
		align-items: center;
		justify-content: center;
		line-height: 16px;
		color: #666;
		font-size: 12px;

		.items {
			margin: 0 6px;
			display: flex;
			align-items: center;

			.q-item {
				width: 6px;
				height: 6px;
				padding: 0;
				margin-right: 8px;
				border-radius: 2px;
				cursor: default;
			}
		}
	}

	.type-wrap {
		margin-top: 14px;

		.title-box {
			padding: 0 16px;
			margin-bottom: 16px;
			line-height: 19px;
			font-size: 14px;
			color: #000;

			.total {
				font-size: 12px;
				color: #666;
			}
		}
	}

	.items-box {
		padding-left: 14px;
		display: flex;
		align-items: center;
		flex-wrap: wrap;

		.q-item {
			margin: 0 10px 10px;
		}
	}
</style>
